package com.joinway.framework.core.json;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;


public class JsonDateSerializer extends JsonSerializer<Date> {

	@Override
	public Class<Date> handledType() {
		return Date.class;
	}

	protected String datePattern = "yyyy-MM-dd";

	@Override
	public void serialize(Date date, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
		gen.writeString(new SimpleDateFormat(getDatePattern()).format(date));
	}

//	public JsonDateTimeSerializer() {
//		super();
//		super.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
//			.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//		super.setDateFormat(new SimpleDateFormat(getDatePattern()));
//	}
//
	public String getDatePattern() {
		return datePattern;
	}

	public void setDatePattern(String datePattern) {
		this.datePattern = datePattern;
	}

}
